<?php
header("content-type:text/html;charset=utf-8");
//数据库连接
$dbhost = 'localhost:3306';  // mysql服务器主机地址
$dbuser = 'root';            // mysql用户名
$dbpass = '';          // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
    die('Could not connect: ' . mysqli_error());
}

$search_input = $_GET['search_input'];

mysqli_select_db( $conn, 'tmp' );  //选择数据库

$sql = "SELECT id, name, class FROM student WHERE id LIKE '$search_input%' OR name LIKE '%$search_input%'";


$retval = mysqli_query( $conn, $sql); 

if(!$retval )
{
    die('无法查询学生: ' . mysqli_error($conn));
}

$str = "<tr><td>序号</td><td>学号</td><td>姓名</td><td>班级</td></tr>";

$st_index = 0;
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC) )
{
    $st_index ++;
    $str = $str . "<tr><td>{$st_index}</td><td>{$row['id']}</td><td>{$row['name']}</td><td>{$row['class']}</td></tr>";
}
if($st_index>0)
{
    $button_display = "visible";
}else
{
    $button_display = "hidden";
}
//$str = $str  . "<tr><td>$search_input</td></tr>";
echo <<<STR
<script>
  window.parent.document.getElementById('search_tb').innerHTML = "$str";
  window.parent.document.getElementById('button_del').style.visibility = '$button_display';
</script>
STR;

?>